/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package dreamwar.view;

import dreamwar.model.POJO.Army;
import javax.swing.JTextField;

/**
 *
 * @author Berto_Romero
 */
public class ArmyBay extends javax.swing.JPanel {

    /**
     * Creates new form ArmyBay
     * @param army
     */
    public ArmyBay(Army army) {
        initComponents();
        this.army = army;
        newArmyNameTextField.setText(army.getArmyName());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        newArmyNameLabel = new javax.swing.JLabel();
        newArmyNameTextField = new javax.swing.JTextField();

        java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
        layout.columnWidths = new int[] {0, 5, 0};
        layout.rowHeights = new int[] {0};
        setLayout(layout);

        newArmyNameLabel.setText("Introduce nuevo nombre:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        add(newArmyNameLabel, gridBagConstraints);

        newArmyNameTextField.setPreferredSize(new java.awt.Dimension(150, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        add(newArmyNameTextField, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    public void updateArmy () {
        String newArmyName = newArmyNameTextField.getText().trim();
        if (!newArmyName.isEmpty()) {
            army.setArmyName(newArmyName);
        }
    }
    
    private final Army army;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel newArmyNameLabel;
    private javax.swing.JTextField newArmyNameTextField;
    // End of variables declaration//GEN-END:variables
}
